﻿using CKS2320.Common.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CKS2412.Controller
{
    public partial class FrmCorrection : Form
    {
        public FrmCorrection()
        {
            InitializeComponent();
        }

        static ParaShowSetModel instance = new ParaShowSetModel();

        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <returns></returns>
        public ParaShowSetModel GetParaShowSetModelConfig()
        {
            string filePath = "ParaSet.json";
            string text = File.ReadAllText(filePath);
            return JsonConvert.DeserializeObject<ParaShowSetModel>(text);
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                instance = GetParaShowSetModelConfig();
                instance.FSOffsetA = Convert.ToDouble(txtFSA.Text);
                instance.FDOffsetA = Convert.ToDouble(txtFDA.Text);
                instance.BSOffsetA = Convert.ToDouble(txtBSA.Text);
                instance.BDOffsetA = Convert.ToDouble(txtBDA.Text);
                instance.SC01OffsetA = Convert.ToDouble(txtFtFSA.Text);
                instance.SC02OffsetA = Convert.ToDouble(txtFtLSA.Text);
                instance.SC03OffsetA = Convert.ToDouble(txtBtFSA.Text);
                instance.SC04OffsetA = Convert.ToDouble(txtBtLSA.Text);
                instance.FSOffsetB = Convert.ToDouble(txtFSB.Text);
                instance.FDOffsetB = Convert.ToDouble(txtFDB.Text);
                instance.BSOffsetB = Convert.ToDouble(txtBSB.Text);
                instance.BDOffsetB = Convert.ToDouble(txtBDB.Text);
                instance.SC01OffsetB = Convert.ToDouble(txtFtFSB.Text);
                instance.SC02OffsetB = Convert.ToDouble(txtFtLSB.Text);
                instance.SC03OffsetB = Convert.ToDouble(txtBtFSB.Text);
                instance.SC04OffsetB = Convert.ToDouble(txtBtLSB.Text);

                instance.FSOffsetA2 = Convert.ToDouble(txtFSA2.Text);
                instance.FDOffsetA2 = Convert.ToDouble(txtFDA2.Text);
                instance.BSOffsetA2 = Convert.ToDouble(txtBSA2.Text);
                instance.BDOffsetA2 = Convert.ToDouble(txtBDA2.Text);
                instance.SC01OffsetA2 = Convert.ToDouble(txtFtFSA2.Text);
                instance.SC02OffsetA2 = Convert.ToDouble(txtFtLSA2.Text);
                instance.SC03OffsetA2 = Convert.ToDouble(txtBtFSA2.Text);
                instance.SC04OffsetA2 = Convert.ToDouble(txtBtLSA2.Text);
                instance.FSOffsetB2 = Convert.ToDouble(txtFSB2.Text);
                instance.FDOffsetB2 = Convert.ToDouble(txtFDB2.Text);
                instance.BSOffsetB2 = Convert.ToDouble(txtBSB2.Text);
                instance.BDOffsetB2 = Convert.ToDouble(txtBDB2.Text);
                instance.SC01OffsetB2 = Convert.ToDouble(txtFtFSB2.Text);
                instance.SC02OffsetB2 = Convert.ToDouble(txtFtLSB2.Text);
                instance.SC03OffsetB2 = Convert.ToDouble(txtBtFSB2.Text);
                instance.SC04OffsetB2 = Convert.ToDouble(txtBtLSB2.Text);

                instance.FCT1OffsetA = Convert.ToDouble(txtFCT1A.Text);
                instance.FCT2OffsetA = Convert.ToDouble(txtFCT2A.Text);
                instance.FCT3OffsetA = Convert.ToDouble(txtFCT3A.Text);
                instance.FCT4OffsetA = Convert.ToDouble(txtFCT4A.Text);
                instance.FCT5OffsetA = Convert.ToDouble(txtFCT5A.Text);
                instance.FCT6OffsetA = Convert.ToDouble(txtFCT6A.Text);
                instance.FCT7OffsetA = Convert.ToDouble(txtFCT7A.Text);
                instance.FCT8OffsetA = Convert.ToDouble(txtFCT8A.Text);
                instance.BCT1OffsetA = Convert.ToDouble(txtBCT1A.Text);
                instance.BCT2OffsetA = Convert.ToDouble(txtBCT2A.Text);
                instance.BCT3OffsetA = Convert.ToDouble(txtBCT3A.Text);
                instance.BCT4OffsetA = Convert.ToDouble(txtBCT4A.Text);
                instance.BCT5OffsetA = Convert.ToDouble(txtBCT5A.Text);
                instance.BCT6OffsetA = Convert.ToDouble(txtBCT6A.Text);
                instance.BCT7OffsetA = Convert.ToDouble(txtBCT7A.Text);
                instance.BCT8OffsetA = Convert.ToDouble(txtBCT8A.Text);

                instance.FCT1OffsetB = Convert.ToDouble(txtFCT1B.Text);
                instance.FCT2OffsetB = Convert.ToDouble(txtFCT2B.Text);
                instance.FCT3OffsetB = Convert.ToDouble(txtFCT3B.Text);
                instance.FCT4OffsetB = Convert.ToDouble(txtFCT4B.Text);
                instance.FCT5OffsetB = Convert.ToDouble(txtFCT5B.Text);
                instance.FCT6OffsetB = Convert.ToDouble(txtFCT6B.Text);
                instance.FCT7OffsetB = Convert.ToDouble(txtFCT7B.Text);
                instance.FCT8OffsetB = Convert.ToDouble(txtFCT8B.Text);
                instance.BCT1OffsetB = Convert.ToDouble(txtBCT1B.Text);
                instance.BCT2OffsetB = Convert.ToDouble(txtBCT2B.Text);
                instance.BCT3OffsetB = Convert.ToDouble(txtBCT3B.Text);
                instance.BCT4OffsetB = Convert.ToDouble(txtBCT4B.Text);
                instance.BCT5OffsetB = Convert.ToDouble(txtBCT5B.Text);
                instance.BCT6OffsetB = Convert.ToDouble(txtBCT6B.Text);
                instance.BCT7OffsetB = Convert.ToDouble(txtBCT7B.Text);
                instance.BCT8OffsetB = Convert.ToDouble(txtBCT8B.Text);


                instance.FCT1OffsetA2 = Convert.ToDouble(txtFCT1A2.Text);
                instance.FCT2OffsetA2 = Convert.ToDouble(txtFCT2A2.Text);
                instance.FCT3OffsetA2 = Convert.ToDouble(txtFCT3A2.Text);
                instance.FCT4OffsetA2 = Convert.ToDouble(txtFCT4A2.Text);
                instance.FCT5OffsetA2 = Convert.ToDouble(txtFCT5A2.Text);
                instance.FCT6OffsetA2 = Convert.ToDouble(txtFCT6A2.Text);
                instance.FCT7OffsetA2 = Convert.ToDouble(txtFCT7A2.Text);
                instance.FCT8OffsetA2 = Convert.ToDouble(txtFCT8A2.Text);
                instance.BCT1OffsetA2 = Convert.ToDouble(txtBCT1A2.Text);
                instance.BCT2OffsetA2 = Convert.ToDouble(txtBCT2A2.Text);
                instance.BCT3OffsetA2 = Convert.ToDouble(txtBCT3A2.Text);
                instance.BCT4OffsetA2 = Convert.ToDouble(txtBCT4A2.Text);
                instance.BCT5OffsetA2 = Convert.ToDouble(txtBCT5A2.Text);
                instance.BCT6OffsetA2 = Convert.ToDouble(txtBCT6A2.Text);
                instance.BCT7OffsetA2 = Convert.ToDouble(txtBCT7A2.Text);
                instance.BCT8OffsetA2 = Convert.ToDouble(txtBCT8A2.Text);

                instance.FCT1OffsetB2 = Convert.ToDouble(txtFCT1B2.Text);
                instance.FCT2OffsetB2 = Convert.ToDouble(txtFCT2B2.Text);
                instance.FCT3OffsetB2 = Convert.ToDouble(txtFCT3B2.Text);
                instance.FCT4OffsetB2 = Convert.ToDouble(txtFCT4B2.Text);
                instance.FCT5OffsetB2 = Convert.ToDouble(txtFCT5B2.Text);
                instance.FCT6OffsetB2 = Convert.ToDouble(txtFCT6B2.Text);
                instance.FCT7OffsetB2 = Convert.ToDouble(txtFCT7B2.Text);
                instance.FCT8OffsetB2 = Convert.ToDouble(txtFCT8B2.Text);
                instance.BCT1OffsetB2 = Convert.ToDouble(txtBCT1B2.Text);
                instance.BCT2OffsetB2 = Convert.ToDouble(txtBCT2B2.Text);
                instance.BCT3OffsetB2 = Convert.ToDouble(txtBCT3B2.Text);
                instance.BCT4OffsetB2 = Convert.ToDouble(txtBCT4B2.Text);
                instance.BCT5OffsetB2 = Convert.ToDouble(txtBCT5B2.Text);
                instance.BCT6OffsetB2 = Convert.ToDouble(txtBCT6B2.Text);
                instance.BCT7OffsetB2 = Convert.ToDouble(txtBCT7B2.Text);
                instance.BCT8OffsetB2 = Convert.ToDouble(txtBCT8B2.Text);


                string content = JsonConvert.SerializeObject(instance);
                string filePath = "ParaSet.json";
                File.WriteAllText(filePath, content);
                MessageBox.Show("Load OK!");
            }
            catch
            {
                MessageBox.Show("Load NG!");
            }
        }

        private void FrmCorrection_Load(object sender, EventArgs e)
        {
            instance = GetParaShowSetModelConfig();
            txtFSA.Text = instance.FSOffsetA.ToString();
            txtFDA.Text = instance.FDOffsetA.ToString();
            txtBSA.Text = instance.BSOffsetA.ToString();
            txtBDA.Text = instance.BDOffsetA.ToString();
            txtFtFSA.Text = instance.SC01OffsetA.ToString();
            txtFtLSA.Text = instance.SC02OffsetA.ToString();
            txtBtFSA.Text = instance.SC03OffsetA.ToString();
            txtBtLSA.Text = instance.SC04OffsetA.ToString();
            txtFSB.Text = instance.FSOffsetB.ToString();
            txtFDB.Text = instance.FDOffsetB.ToString();
            txtBSB.Text = instance.BSOffsetB.ToString();
            txtBDB.Text = instance.BDOffsetB.ToString();
            txtFtFSB.Text = instance.SC01OffsetB.ToString();
            txtFtLSB.Text = instance.SC02OffsetB.ToString();
            txtBtFSB.Text = instance.SC03OffsetB.ToString();
            txtBtLSB.Text = instance.SC04OffsetB.ToString();

            txtFCT1A.Text = instance.FCT1OffsetA.ToString();
            txtFCT2A.Text = instance.FCT2OffsetA.ToString();
            txtFCT3A.Text = instance.FCT3OffsetA.ToString();
            txtFCT4A.Text = instance.FCT4OffsetA.ToString();
            txtFCT5A.Text = instance.FCT5OffsetA.ToString();
            txtFCT6A.Text = instance.FCT6OffsetA.ToString();
            txtFCT7A.Text = instance.FCT7OffsetA.ToString();
            txtFCT8A.Text = instance.FCT8OffsetA.ToString();
            txtBCT1A.Text = instance.BCT1OffsetA.ToString();
            txtBCT2A.Text = instance.BCT2OffsetA.ToString();
            txtBCT3A.Text = instance.BCT3OffsetA.ToString();
            txtBCT4A.Text = instance.BCT4OffsetA.ToString();
            txtBCT5A.Text = instance.BCT5OffsetA.ToString();
            txtBCT6A.Text = instance.BCT6OffsetA.ToString();
            txtBCT7A.Text = instance.BCT7OffsetA.ToString();
            txtBCT8A.Text = instance.BCT8OffsetA.ToString();

            txtFCT1B.Text = instance.FCT1OffsetB.ToString();
            txtFCT2B.Text = instance.FCT2OffsetB.ToString();
            txtFCT3B.Text = instance.FCT3OffsetB.ToString();
            txtFCT4B.Text = instance.FCT4OffsetB.ToString();
            txtFCT5B.Text = instance.FCT5OffsetB.ToString();
            txtFCT6B.Text = instance.FCT6OffsetB.ToString();
            txtFCT7B.Text = instance.FCT7OffsetB.ToString();
            txtFCT8B.Text = instance.FCT8OffsetB.ToString();
            txtBCT1B.Text = instance.BCT1OffsetB.ToString();
            txtBCT2B.Text = instance.BCT2OffsetB.ToString();
            txtBCT3B.Text = instance.BCT3OffsetB.ToString();
            txtBCT4B.Text = instance.BCT4OffsetB.ToString();
            txtBCT5B.Text = instance.BCT5OffsetB.ToString();
            txtBCT6B.Text = instance.BCT6OffsetB.ToString();
            txtBCT7B.Text = instance.BCT7OffsetB.ToString();
            txtBCT8B.Text = instance.BCT8OffsetB.ToString();

        }
    }
}
